package com.pfzy.lib.common.http.util;

import android.widget.Toast;

import com.pfzy.lib.sdk.utils.Common;

import java.util.HashMap;

public class HttpUtils {
    public static void onFail(boolean showError, int code, String message) {
        if (code == -1006 || code == -1005) {
            Toast.makeText(Common.getContext(), "网络繁忙", Toast.LENGTH_SHORT).show();
        } else if (showError) {
            Toast.makeText(Common.getContext(), message, Toast.LENGTH_SHORT).show();
        }
        trackWhenFailed(code, message);
    }

    public static String getFailMessage(int code, String message) {
        return (code == -1006 || code == -1005) ? "网络繁忙" : "" + message;
    }

    public static void trackWhenFailed(int code, String message) {
        HashMap<String, String> customMap = new HashMap<>();
        customMap.put("error_code", "" + code);
        customMap.put("error_message", "" + message);
        customMap.put("network_type", "" + "");
    }
}